﻿// $Id$
/*
 *  Copyright (C) 2007 NourY Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */

using System;
using System.Data.Common;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NHibernate;
using NHibernate.Cfg;
using Northwind.DomainModel.NHibernate;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Salamanca.NUnit.DataAccess.Northwind.NHibernate
{

    [TestClass]
    public class DataAccess
    {
        public DataAccess()
        {
        }

        [ClassInitialize]
        public static void Initialize(TestContext context)
        {
            _Database=new global::Northwind.DomainModel.Data.NorthwindDb(global::Northwind.NorthwindDatabaseType.SQLite);
            _SessionFactory=new Configuration()
                .Configure()
                .AddResource(typeof(Customer).FullName, typeof(Customer).Assembly)
                .BuildSessionFactory();
        }

        [ClassCleanup]
        public static void Cleanup()
        {
            _Database.Dispose();
        }

        // Utilisez TestInitialize pour exécuter du code avant d'exécuter chaque test 
        [TestInitialize()]
        public void SetUp()
        {
            DbConnection connection=_Database.Connection;
            connection.Open();
            _Session=_SessionFactory.OpenSession(connection);
        }


        // Utilisez TestCleanup pour exécuter du code après que chaque test a été exécuté
        [TestCleanup()]
        public void TearDown()
        {
            _Session.Close();
        }


        [TestMethod]
        public void CanFindAllElements()
        {
            IList<Customer> list=Session.CreateCriteria<Customer>().List<Customer>();

            Assert.AreEqual(91, list.Count);
        }

        protected ISession Session
        {
            get
            {
                return _Session;
            }
        }

        private ISession _Session;

        private static global::Northwind.DomainModel.Data.NorthwindDb _Database;
        private static ISessionFactory _SessionFactory;
    }
}
